//
//  MainViewController.swift
//  SinaWeiBo
//
//  Created by yz on 16/1/29.
//  Copyright © 2016年 yz. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    
    @objc private func composeBtnDidClick()
    {
        print(__FUNCTION__)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    
        //添加子视图控制器
        
        let mainTabBar = MainTabBar()
        
        setValue(mainTabBar, forKey: "tabBar")
        
        addChildViewControllers()
        
        mainTabBar.composeBtn.addTarget(self, action: "composeBtnDidClick", forControlEvents: .TouchUpInside)
        
        
    }
    
    private  func addChildViewControllers() {
        
//        let home = HomeTableViewController()
//        
//        home.title = "首页"
//        
//        home.tabBarItem.image = UIImage(named: "tabbar_home")
//        
//        home.view.backgroundColor = UIColor.yellowColor()
//        
//        let homeNav = UINavigationController(rootViewController: home)
//        
//        addChildViewController(homeNav)
//        
//        let message = MessageTableViewController()
//        
//        message.view.backgroundColor = UIColor.purpleColor()
//        
//        let messageNav = UINavigationController(rootViewController: message)
//        
//        addChildViewController(messageNav)
//        
//        let discover = DiscoverTableViewController()
//        
//        discover.view.backgroundColor = UIColor.blackColor()
//        
//        let discoverNav = UINavigationController(rootViewController: discover)
//        
//        addChildViewController(discoverNav)
//        
//        let profile = ProfileTableViewController()
//        
//        profile.view.backgroundColor = UIColor.orangeColor()
//        
//        let profileNav = UINavigationController(rootViewController: profile)
//        
//        addChildViewController(profileNav)
        
        addChildViewController(HomeTableViewController(), title:"首页", normalImage: "tabbar_home", selectImage: "tabbar_home_highlighted")
        
        addChildViewController(MessageTableViewController(), title: "消息", normalImage: "tabbar_message_center", selectImage: "tabbar_message_center_highlighted")
        
        addChildViewController(DiscoverTableViewController(), title: "发现", normalImage: "tabbar_discover", selectImage: "tabbar_discover_highlighted")
    
        addChildViewController(ProfileTableViewController(), title: "我", normalImage: "tabbar_profile", selectImage: "tabbar_profile_highlighted")
    }
    
    private  func addChildViewController(vc:UIViewController,title:String,normalImage:String,selectImage:String)
        
        {
            
            let nav = UINavigationController(rootViewController: vc);
            
            vc.title = title
            
            vc.tabBarItem.image = UIImage(named: normalImage)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
            
            vc.tabBarItem.selectedImage = UIImage(named:selectImage)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
            
            vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
            
            addChildViewController(nav)
            
        }
    
}
